//
//  XYUIButton+Extension.swift
//  WeiboSourceCode
//
//  Created by 周星宇 on 15/12/28.
//  Copyright © 2015年 cn.weibo. All rights reserved.
//

import UIKit

extension UIButton {
    
    convenience init(title: String?, image: String?){
        
        self.init()
        if title != nil {
            
            setTitle(title, forState: .Normal)
    
        }
        if image != nil {
            
            setBackgroundImage(UIImage(named: image!), forState: .Normal)
        }
        
    }
    convenience init(title: String, fontSize: CGFloat, color: UIColor, imageName: String?, backColor: UIColor? = nil) {
        self.init()
        
        setTitle(title, forState: .Normal)
        setTitleColor(color, forState: .Normal)
        
        if let imageName = imageName {
            setImage(UIImage(named: imageName), forState: .Normal)
        }
        
        // 设置背景颜色
        backgroundColor = backColor
        
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        
        sizeToFit()
    }

}
extension UILabel {
    
    convenience init(textColor: UIColor, fontSize: CGFloat) {
        self.init()
        self.textColor = textColor
        self.font = UIFont.systemFontOfSize(fontSize)
    }
    
}

extension UIButton {
    convenience init(textColor: UIColor, fontSize: CGFloat) {
        self.init()
        self.setTitleColor(textColor, forState: UIControlState.Normal)
        self.titleLabel?.font = UIFont.systemFontOfSize(fontSize)
    }
}
